﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Wjtour.Domain;
using Wjtour.BLL;
using Hjp.FrameWork.Common;
using Wjtour.Common;

namespace Wjtour.Web.Admin.traffic
{
    public partial class list : BasePage
    {
        #region 固定分页参数
        private int page = 1;
        private int pagesize = 20;
        #endregion

        traffic_bll _bll = new traffic_bll();
        protected PaginationData<Wjtour.Domain.traffic> data = new PaginationData<Domain.traffic>();
        protected TextBox q;
        protected DropDownList cid;
        protected Button submit;
        protected HiddenField delIds;
        protected Button delButton;
        protected string traffictype;
        protected Dictionary<string, string> dic = new Dictionary<string, string>();

        protected void Page_Load(object sender, EventArgs e)
        {
            page = Utils.StrToInt(Request["page"], 1);
            traffictype = Request["type"];
            submit.Click += new EventHandler(submit_Click);
            delButton.Click += new EventHandler(delButton_Click);
            bindList();
            if (!IsPostBack)
            {
                BindDropdown();
                //cid.SelectedValue = traffictype;
                q.Text = Request["q"];
            }
            dic.Clear();
            dic.Add("1", "城市地图");
            dic.Add("2", "公交线路");
            dic.Add("3", "出租车");
            dic.Add("4", "周边机场");
        }

        void delButton_Click(object sender, EventArgs e)
        {
            bool b = _bll.BatchDelete(delIds.Value) > 0;

            if (b)
            {
                SaveLog("Delete[" + delIds.Value + "]");
                Utils.Alert(this.Page, "删除成功！");
                Utils.Redirect(this.Page, "list.aspx?type=" + traffictype + "&q=" + q.Text, false);
            }
        }


        void BindDropdown()
        {
            cid.Items.Add(new ListItem("城市地图", "1"));
            cid.Items.Add(new ListItem("公交线路", "2"));
            cid.Items.Add(new ListItem("出租车", "3"));
            cid.Items.Add(new ListItem("周边机场", "4"));
        }

        void submit_Click(object sender, EventArgs e)
        {
            bindList();
        }

        void bindList()
        {
            string t = cid.SelectedValue.ToString() == "0" ? traffictype : cid.SelectedValue.ToString();
            data = _bll.GetList(q.Text, t, page - 1, pagesize);
            PagerHtml = Utility.pageft(data.Pager.TotalRecords, "/admin/traffic/list.aspx?type=" + t + "&q=" + HttpUtility.UrlEncode(q.Text), pagesize);
        }
    }
}